home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 01/07/2000
- // Author: zguo
- //
- // Procedure Name:
- // clipGraphEditor
- //
- // Description:
- // Open the graph editor for the anim curves of the selected clips
- // in the clipEditor.
- //
- // Input Arguments:
- // $editor - The Trax Editor.
- //
- // Return Value:
- // None.
- //
-
- proc string[] clipGraphEdSelectClips( string $editor )
- {
- string $clipNameList[];
-
- // Get clip index and scheduler from the clipEditor.
- //
- string $clips[] = `clipEditor -q -sc $editor`;
- int $numClips = size( $clips );
-
- // If no clip was selected, return. If there is one clip selected,
- // clipEditor returns two strings: schedulerName and clip index.
- //
- if( $numClips <= 1 )
- return $clipNameList;
-
- int $sInd = 0;
- int $cInd = 0;
- int $clipIndices[];
- string $scheduler[];
- for( $i = 0; $i < $numClips; $i +=2 )
- {
- $scheduler[$sInd] = $clips[$i];
- $clipIndices[$cInd] = $clips[$i + 1];
-
- $sInd ++;
- $cInd ++;
- }
-
- // Get clip names from their index.
- //
- int $numIndices = size( $clipIndices );
- for( $i = 0; $i < $numIndices; $i ++ )
- {
- $clipNameList[$i] =
- `clipSchedule -ci $clipIndices[$i] -q -n $scheduler[$i]`;
- }
-
- return $clipNameList;
- }
-
-
- proc string[] clipGraphEdSelectBlends( string $editor )
- {
- string $blendNodeList[];
-
- // Get blends index and scheduler from the clipEditor.
- //
- string $blends[] = `clipEditor -q -sb $editor`;
- int $numBlends = size( $blends );
-
- // If no blend was selected, return. If there is one blend selected,
- // clipEditor returns three strings: schedulerName and two clip indices.
- //
- if( $numBlends <= 2 )
- return $blendNodeList;
-
- int $sInd = 0;
- int $bInd1 = 0;
- int $bInd2 = 0;
- int $bInds1[];
- int $bInds2[];
- string $schs[];
- for( $i = 0; $i < $numBlends; $i +=3 )
- {
- $schs[$sInd] = $blends[$i];
- $bInds1[$bInd1] = $blends[$i + 1];
- $bInds2[$bInd2] = $blends[$i + 2];
-
- $sInd ++;
- $bInd1 ++;
- $bInd2 ++;
- }
-
- // Get clip names from their index.
- //
- int $bIndex = 0;
- string $bName[];
- int $numIndices = size( $bInds1 );
- for( $i = 0; $i < $numIndices; $i ++ )
- {
- $bName = `clipSchedule -bn $bInds1[$i] $bInds2[$i] -q -n $schs[$i]`;
- int $nBlends = `size($bName)`;
- for ($jj = 0; $jj < $nBlends; $jj++) {
- $blendNodeList[$bIndex++] = $bName[$jj];
- }
- }
-
- return $blendNodeList;
- }
-
- proc int isVisible(string $graphEd, int $forceOpen)
- //
- // Description:
- // Returns 1 if the specified graphEditor is visible, otherwise
- // 0 is returned.
- // If the editor is in the main window, but the main window is
- // minimized, the editor is not considered visible. If the editor
- // is in its own window and that window is minimized, the editor
- // is considered visible.
- //
- // If the $forceOpen argument is used, if a main Maya window is
- // found and it is iconified, it is expanded.
- //
- {
- string $parentLayout = `editor -q -p $graphEd`;
- if (`size($parentLayout)` == 0) {
- return false;
- }
-
- string $buff[];
- tokenize($parentLayout, "|", $buff);
-
- // The main Maya window is a special case.
- if (`window -q -mw $buff[0]`) {
- if (`window -q -i $buff[0]`) {
- if ($forceOpen) {
- showWindow $buff[0];
- } else {
- // No editors are visible in the main window.
- //
- return false;
- }
- }
-
- string $visiblePanels[] = `getPanel -vis`;
- string $graphEdPanel = `editor -q -panel $graphEd`;
-
- string $visItem;
- int $found = false;
-
- for ($visItem in $visiblePanels) {
- if ($visItem == $graphEdPanel) {
- $found = true;
- break;
- }
- }
-
- return $found;
- }
-
- return true;
- }
-
- proc string availibleGraphEditor(int $forceOpen)
- //
- // Description:
- // Returns an avalible Graph Editor. This procedure assumes that the
- // Graph Editor names are in the form of graphEditor#GraphEd,
- // which is their default.
- //
- // If a Graph Editor is not found, "" is returned.
- //
- // If a Graph Editor is set to not Auto Load selected objects
- // it is considered unavalible.
- //
- {
- string $regexp = "graphEditor[0-9]*GraphEd$";
- string $item;
- string $searchResultList[];
-
- int $nMatch = 0;
- string $editors[] = `lsUI -ed`;
- string $sorted[] = `sort($editors)`;
- for ($item in $sorted) {
- string $searchResult = match($regexp, $item);
- if( $searchResult == $item) {
- $searchResultList[$nMatch++] = $searchResult;
- }
- }
-
- if ($nMatch == 0) {
- return "";
- }
-
- // Get rid of all of the editors that are not currently displayed.
- //
- int $i;
- int $nEditors = 0;
- string $graphEditorList[];
- string $candidateGraphEditor;
- for ($i = 0; $i < $nMatch; $i++) {
- // Only editors that are created should be considered.
- //
- if (isVisible($searchResultList[$i], $forceOpen)) {
- // Avoid the ones with auto load off.
- //
- string $mlc = `editor -q -mlc $searchResultList[$i]`;
- string $outline = `selectionConnection -q -p $mlc`;
- if (isAutoLoad($outline)) {
- $graphEditorList[$nEditors++] = $searchResultList[$i];
-
- // Only one Graph Editor is needed.
- break;
- } else {
- if (`size($candidateGraphEditor)` == 0) {
- $candidateGraphEditor = $searchResultList[$i];
- }
- }
- }
- }
-
- string $graphEditor = "";
- if (size($graphEditorList) == 0) {
- if (size($candidateGraphEditor) == 0) {
- $graphEditor = "";
- } else {
- $graphEditor = $candidateGraphEditor;
- }
- } else {
- $graphEditor = $graphEditorList[0];
- }
-
- if (!$forceOpen && size($graphEditor) == 0) {
- // Check one more time, this time if the main Maya window is
- // encountered and it is iconified, force it open.
- //
- $graphEditor = availibleGraphEditor(true);
- }
-
- // Return the graphEditor, if it was found.
- //
- return $graphEditor;
- }
-
-
- global proc clipGraphEditor( string $editor )
- {
- // 1. Find an avalible editor, if one does not exist, create one.
- // 2. Get the clips to display.
- // 3. Get the blends to display.
- // 4. If window is minimized, expand
- // 5. Change the selected items in the outliner
- // 6. Change the selected items in the editor.
- // 7. Frame the view.
-
- // Get the clips selected in the Trax Editor.
- //
- string $clipNodeList[] = clipGraphEdSelectClips($editor);
-
- // Get the blends selected in the Trax Editor.
- //
- string $blendNodeList[] = clipGraphEdSelectBlends($editor);
-
- // Get a Graph Editor and the Graph Editor Outline
- //
- string $graphEditor = availibleGraphEditor(false);
- if (`size($graphEditor)` == 0) {
- GraphEditor;
- $graphEditor = availibleGraphEditor(false);
-
- if (`size($graphEditor)` == 0) {
- error("Could not get the Graph Editor.");
- }
- }
-
- string $editorMLC = `editor -q -mlc $graphEditor`;
- string $graphEditorOutliner = `selectionConnection -q -p $editorMLC`;
-
- // If the Graph Editor is iconified, expand it.
- //
- string $parentLayout = `editor -q -p $graphEditor`;
- string $buff[];
- tokenize($parentLayout, "|", $buff);
-
- // If this is not the main window, bring it to the front.
- //
- if (!`window -q -mw $buff[0]`) {
- showWindow $buff[0];
- }
-
- int $nClips = `size($clipNodeList)`;
- int $nBlends = `size($blendNodeList)`;
- int $nSelected = $nClips + $nBlends;
- if ($nSelected > 0) {
- // Clear the selection list.
- //
- select -cl;
-
- // Add the selected blends and display in the editor.
- //
- for ($i = 0; $i < $nBlends; $i++) {
- select -add $blendNodeList[$i];
- }
-
- // Add the selected clips and display in the editor.
- //
- for ($i = 0; $i < $nClips; $i++) {
- select -add $clipNodeList[$i];
- }
- }
-
- // Update the Graph Editor and Graph Editor Outliner.
- //
- if (!isAutoLoad($graphEditorOutliner)) {
- doReload($graphEditorOutliner);
- }
-
- int $editorLocked = `selectionConnection -query -lock $editorMLC`;
- if ($editorLocked) {
- editor -edit -unlockMainConnection $graphEditor;
- }
-
- editor -edit -mlc animationList $graphEditor;
-
- // Frame the view.
- //
- animCurveEditor -e -la "selected" $graphEditor;
-
- // Restore the mainListConnection to the graph editor.
- //
- editor -edit -mlc $editorMLC $graphEditor;
- if ($editorLocked) {
- editor -edit -lockMainConnection $graphEditor;
- }
- }
-